<?php


$dateToday=date("Y-m-d");
$csvsfolder = "./csvs/";
$filename="testuploadcsv.csv";
$filename=$_GET['filename'];


$orgFile = fopen($csvsfolder.$filename,"r");
$counter=0;
$abnormal = 1;
$numberExist = 0;
$key = 0;
$arrProducts = array();
while(($lineData = fgetcsv($orgFile,0))!= FALSE){
	if($counter>0){ 
		if(trim($lineData[12])!=""){
		$key = array_search($lineData[12],$arrProducts);
		
		if($key === FALSE){
			$arrProducts[] = $lineData[12];
			$arrProducts[] = $lineData[0];
			$arrProducts[] = $lineData[14];
			$arrProducts[] = $lineData[15];
			$arrProducts[] = $lineData[31];
			$arrProducts[] = $lineData[30];			
			}
		else{
			$arrProducts[$key + 1] .= " | ".$lineData[0]; 
			$arrProducts[$key + 3] += (int)$lineData[15];
			$arrProducts[$key + 5] .= " | ".$lineData[30]; 
			}	
		}
	}
	$counter++;
}


//var_dump($arrProducts);

?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title><?php echo $dateToday; ?> Waiting For Post </title>
</head>

<body style="margin:5;font-family:Arial;">
<H2>Pick Up Summary on <?php echo $dateToday;?> for <?php echo $filename ?>   Sign By :_____________</H2>
<table width="1060" border="1" cellspacing="0" cellpadding="0" style="font-family:Arial; font-size:12px;
border-color:#666; border-style:solid border-width:1px;">
  <tr>  
    <td align="center" style="width:50px;" > No</td>
    <td style="width:90px;" >#Location</td>
    <td style="width:90px;" > Stock</td>
    <td style="width:180px;" > Order ID</td>
    <td style="width:70px;">Thumb</td>
    <td style="width:200px;">Title</td>
    <td style="width:30px;">Qty</td>
    <td style="width:200px;">Barcode</td>
    <td style="width:50px;">Color Comment </td>
    <td style="width:150px;">Picked Up / Transfer Note</td>
  </tr>
<?php
$cot = 1;
$total = 0;
foreach($arrProducts as $key => $value){
if($key%6==0){
	$location = file_get_contents('http://approd9h4leb60v4olh1v.phonecollection.com.au/stock/get-product-location/barcode/'.trim($arrProducts[$key +4]));
	$whStock = file_get_contents('http://192.168.1.126/products/get-current-stock/barcode/'.trim($arrProducts[$key +4]));
	
?>  
  <tr>  	
    <td align="center" style="width:50px;" ><?php echo $cot++;?></td>
    <td align="center" style="width:90px;" ><?php echo " ".$location ?></td>
    <td align="center" style="width:90px;" ><?php echo " ".$whStock ?></td>
    <td style="width:180px;" ><?php echo $arrProducts[$key +1];?></td>
    <td><img src="http://thumbs.ebaystatic.com/pict/<?php echo $arrProducts[$key];?>6464_.jpg" border="0" /></td>
    <td><?php echo $arrProducts[$key +2];?></td>
    <td><?php echo $arrProducts[$key +3]; $total += $arrProducts[$key +3]; ?></td>
    <td><?php echo $arrProducts[$key +4];?></td>
    <td><?php echo $arrProducts[$key +5];?></td>
    <td>&nbsp;</td>
  </tr>
<?php
	}
}
?>
</table>
<br />
Total Pcs: <?php echo $total;?>
</body>
</html>